﻿@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
    YJ.Platform.Documents Doc = new YJ.Platform.Documents();
    YJ.Platform.DocumentDirectory DocDir = new YJ.Platform.DocumentDirectory();
    string DirID = Request.QueryString["dirid"];
    bool HasManage = DocDir.HasManage(DirID.ToGuid(), YJ.Platform.Users.CurrentUserID);
    bool HasPublish = DocDir.HasPublish(DirID.ToGuid(), YJ.Platform.Users.CurrentUserID);
}

<form id="form1">
@Html.AntiForgeryToken()
<div class="querybar">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td>
            标题：<input type="text" class="mytext" id="Title1" name="Title1" runat="server" style="width:200px" />
            发布时间：<input type="text" class="mycalendar" id="Date1" name="Date1" runat="server" style="width:80px" />
            至 <input type="text" class="mycalendar" id="Date2" name="Date2" runat="server" style="width:80px" />
            <input type="button" class="mybutton" onclick="query(null, 1);" value="&nbsp;查询&nbsp;" />
            @if(HasPublish){
            <input type="button" class="mybutton" onclick="window.location = 'DocAdd?1=1@(ViewBag.Query)';" value="添加文档" />
            }
            @if(HasManage){
            <input type="button" class="mybutton" value="编辑栏目" onclick="window.location='DirAdd?currentdirid=@DirID@(ViewBag.Query)';"/>
            <input type="button" class="mybutton" value="添加子栏目" onclick="window.location='DirAdd?1=1@(ViewBag.Query)';" />
            }
        </td>
    </tr>
</table>
</div>
<table id="listtable"></table>
<div class="buttondiv"></div>
</form>
<script type="text/javascript">
    var curPageSize, curPageNumber;
    var dirid="@Request.QueryString["dirid"]";
    $(function ()
    {
        $("#listtable").jqGrid({
            url: RoadUI.Core.rooturl() + "/Documents/Query",
            postData: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val(), DirID: dirid, 
                pagesize:"@Request.QueryString["pagesize"]", pagenumber:"@Request.QueryString["pagenumber"]" },
            mtype: 'POST',
            datatype: "json",
            colNames: ['标题', '栏目', '发布人', '发布时间', '阅读次数'],
            colModel: [
                { name: 'Title', index: 'Title', width: 350 },
                { name: 'DirectoryName', index: 'DirectoryName', align: "left", width: 110 },
                { name: 'WriteUserName', index: 'WriteUserName', align: "left", width: 90 },
                { name: 'WriteTime', index: 'WriteTime', align: "left", width: 110 },
                { name: 'ReadCount', index: 'ReadCount', align: "left", width: 40 }
            ],
            //rownumbers: true,//显示序号列
            sortname: "WriteTime",
            sortorder: "desc",
            height: '100%',
            width: $(window).width(),
            loadComplete: function ()
            {
                var gridObj = $("#listtable");
                var records = gridObj.getGridParam("userData");
                curPageSize = records.pagesize;
                curPageNumber = records.pagenumber;
                $(".buttondiv").html(RoadUI.Core.getPager1(records.total, records.pagesize, records.pagenumber, "query"));
            }
        });
    });
    $(window).resize(function(){  
        $("#listtable").setGridWidth($(window).width());
    });
    function query(size, number)
    {
        var data = {
            __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val(),
            Title1: $("#Title1").val(),
            Date1: $("#Date1").val(), Date2: $("#Date2").val(), DirID: dirid,
            pagesize: size, pagenumber: number
        };
        $("#listtable").setGridParam({ postData: data }).trigger("reloadGrid");
    }
    function showDoc(id, title)
    {
        window.location='DocRead?docid=' + id + "@(Html.Raw(ViewBag.Query))&pagesize="+curPageSize+"&pagenumber="+curPageNumber;
    }
    function checkdel()
    {
        if($(":checked[name='docbox']").size()==0)
        {
            alert('您没有选择要删除的文档!');
            return false;
        }
        return confirm('您真的删除所选的文档吗?');
    }
</script>
